import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, HydratedDocument, Types } from 'mongoose';
import { User } from './user.entity';

export type GroupDocument = HydratedDocument<Group>;

@Schema()
export class Group extends Document {
  @Prop({ type: Types.ObjectId, ref: () => User.name })
  userId: Types.ObjectId | User | string; // 群主id

  @Prop({ type: String, required: true })
  groupName: string; // 群名称

  @Prop({ type: Number })
  groupNumber: number; // 群号

  @Prop({ type: String, required: true })
  sign: string; // 群简介

  @Prop({ type: String, default: '/group_pic.png' })
  imgUrl: string; // 群头像

  @Prop({ type: String, default: Date.now })
  creatTime: string; // 创建时间

  @Prop([{ type: Types.ObjectId, ref: 'User' }])
  groupUsers: Types.ObjectId[];
}

export const GroupSchema = SchemaFactory.createForClass(Group);
